import React from "react";
import { useNavigate } from "react-router-dom";
import { Button, Input, Form, Toast, NavBar } from "react-vant";
import axios from "axios";
const Index: React.FC = () => {
  const [form] = Form.useForm();
  const navigate = useNavigate();

  const onFinish = (values: any) => {
    axios.post("/api/sigin", values).then((resp) => {
      console.log(resp);
      let { code, msg } = resp.data;
      if (code == 200) {
        Toast.success(msg);
        navigate("/login");
      } else {
        Toast.success(msg);
      }
    });
  };

  return (
    <div>
      <NavBar title="注册" leftArrow={false} />
      <Form
        form={form}
        onFinish={onFinish}
        footer={
          <div style={{ margin: "16px 16px 0" }}>
            <Button round nativeType="submit" type="primary" block>
              注册
            </Button>
          </div>
        }
      >
        <Form.Item
          tooltip={{
            message:
              "A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.",
          }}
          intro="确保这是唯一的用户名"
          rules={[{ required: true, message: "请填写用户名" }]}
          name="username"
          label="用户名"
        >
          <Input placeholder="请输入用户名" />
        </Form.Item>
        <Form.Item
          rules={[{ required: true, message: "请填写密码" }]}
          name="password"
          label="密码"
        >
          <Input placeholder="请输入密码" />
        </Form.Item>
      </Form>
    </div>
  );
};
export default Index;
